package com.ruicar.afs.cloud.afscase.approvetask.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.afscase.approvetask.condition.WaitTaskPoolCondition;
import com.ruicar.afs.cloud.afscase.approvetask.condition.WorkTaskPoolCondition;
import com.ruicar.afs.cloud.afscase.approvetask.entity.WorkTaskPool;
import com.ruicar.afs.cloud.afscase.approvetask.vo.ApproveTaskVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.CaseBaseInfoVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.NoOperateTaskVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.WaitTaskVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-05-17 10:39
 */
public interface WorkTaskPoolMapper extends BaseMapper<WorkTaskPool> {
    //待分配任务
    IPage<WaitTaskVO> getAllWaitTaskList(Page page, @Param("waitTaskPoolCondition") WaitTaskPoolCondition waitTaskPoolCondition);

    //公共任务池
    IPage<ApproveTaskVo> queryCommonPoolTaskList(Page page, @Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);

    //审批待办件
    IPage<ApproveTaskVo> queryApproveTaskList(Page page, @Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);

    //组长待办
    IPage<ApproveTaskVo> queryGroupLeaderTaskList(Page page, @Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);

    //案件信息
    IPage<CaseBaseInfoVo> queryCaseInfoTaskList(Page page, @Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);
    //特殊任务池
    IPage<ApproveTaskVo> querySpecialPoolTaskList(Page page, @Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);

    //锁定
    Integer modifyLock(@Param("waitTaskVOList") List waitTaskVOList, @Param("status") String status);

    //置顶
    Integer modifyStick(@Param("waitTaskVOList") List waitTaskVOList, @Param("status") String status);

    /**
     * 无操作待办任务列表
     * */
    List<String> queryNoOperateApproveTaskList(@Param("workTaskPoolCondition") WorkTaskPoolCondition workTaskPoolCondition);

    /**
     * 查询审批流程任务列表
     * @author ma_xueyu
     * @param applyNo 申请编号
     * */
    @Select({" select * from work_task_pool where apply_no=#{applyNo} and stage_id=#{scheduleId} ORDER BY create_time "})
    List<WorkTaskPool> getWorkTaskListByCondition(@Param("applyNo") String applyNo,@Param("scheduleId") String scheduleId);

    /**
     * 查询审批流程的下一待办任务
     * @author ma_xueyu
     * @param applyNo 申请编号
     * @param scheduleId 流程实例表ID
     * @param approveStaff 经办人（撤回申请人）
     * */
    @Select({" select * from  work_task_pool where start_time> " +
            "(select MAX(pool.start_time) from work_task_pool as pool where pool.apply_no=#{applyNo} and pool.stage_id=#{scheduleId} " +
            "and pool.approve_staff=#{approveStaff}) and apply_no=#{applyNo} and stage_id=#{scheduleId} ORDER BY start_time LIMIT 0,1"})
    WorkTaskPool getNextWorkTaskByCondition(@Param("applyNo") String applyNo,@Param("scheduleId") String scheduleId,@Param("approveStaff") String approveStaff);


    /**
    * @Description 获取当前所有常规流程任务
    * @Author Peng_Jinbo
    * @Date 2020/10/12 16:49
    */
    List<WorkTaskPool> listAllNormalFlowPool(@Param("businessStateIn")String businessStateIn,@Param("processType")String processType);
}
